function getIndex(index,length){
    layui.use(['table','layer'], function () {
        var table = layui.table;
        var layer = layui.layer;

        table.render({
            elem: '#test'
            , id:'testReload'
            , url: 'jay/Goods/getGoodsList'
            , parseData: function (res) {
                return {
                    "code": 0, //解析接口状态
                    "msg": "", //解析提示文本
                    "count": res.obj.total, //解析数据长度
                    "data": res.obj.list //解析数据列表
                };
            }
            , toolbar: '#toolbarDemo'
            , title: '商品数据表'
            , totalRow: true
            , cols: [
                [
                    { type: 'radio' , fixed: 'left'}
                    , { field: 'id', title: '序号', sort: true, width:80,align:'center' }
                    , { field: 'goodsName', title: '商品名称' ,align:'center'}
                    , { field: 'specificationName', title: '商品规格单位' ,align:'center'}
                    , { field: 'available', title: '库存' ,align:'center'}
                    , { field: 'salesPrice', title: '销售单价',align:'center' }
                ]
            ]
            , page: true
            , limit: 3
            , limits: ['3', '5', '7']
        });
        var $ = layui.$,active={
            reload:function(){
                table.reload('testReload',{
                    page:{
                        curr:1//默认从第一页开始加载
                    },
                    where:{
                        goodsName:$('#goodsName').val()
                    }
                });
            }
        };
        $('#find').on('click', function(){
            var type = 'reload';
            active[type] ? active[type].call(this) : '';
        });

        table.on('toolbar(test)', function (obj) {
            var checkStatus = table.checkStatus(obj.config.id);
            var data = checkStatus.data[0];
            var flag = false;

            switch (obj.event) {
                case 'close' :
                    parent.layer.close(parent.layer.getFrameIndex(window.name));
                    break;

                case 'getCheckData':
                    parent.getDetail(data);
                    if(data==undefined){
                        layer.msg("请选择商品",{icon:2})
                    }else if(data!=undefined) {//若勾选了内容
                        for (var i = 1; i < length; i++) {
                            if (parent.layui.$("#goodsId" + i).val() == data.goodsId) {//如果父页面有该商品的id
                                flag = true
                            }
                        }
                        if(flag == true){
                            layer.msg("该商品已被选择，请移步到订单主页面修改数量!", {icon: 2})
                        }
                        if(flag == false){
                            parent.layui.$("#goodsId"+index).val(data.goodsId);//商品id
                            parent.layui.$("#goodsName"+index).val(data.goodsName);//商品名称
                            parent.layui.$("#salesPrice"+index).val(data.salesPrice);//单件售价
                            parent.layui.$("#available"+index).val(data.available);//库存
                            parent.layer.close(parent.layer.getFrameIndex(window.name));
                        }
                    }
                    break;

            }
        });
    });
}
